<?php

abstract class Topic {

	/**
	 * @var int
	 */
	protected $topicId;
	
	/**
	 * @var int
	 */
	protected $userId;
	
	/**
	 * @var String
	 */
	protected $title;
	
	/**
	 * @var Timestamp
	 */
	protected $created;
	
	
	/**
	 * @var int
	 */
	private $voteCnt;
	
	/**
	 * @var boolean
	 */
	private $yetVoted;
	
	
	public function Topic($topicId, $userId, $title, $created, $voteCnt, $yetVoted) {
		$this->topicId = $topicId;
		$this->userId = $userId;
		$this->title = $title;
		$this->created = $created;
		$this->voteCnt = $voteCnt;
		$this->yetVoted = $yetVoted;
	}
	
	public abstract function toXmlString();
	
	protected final function xmlStringTemplate($tagName, $subId, $subCategoryId) {
		return
		'<'.$tagName.' '.$tagName.'Id="' . $subId . '" TopicId="' . $this->topicId . '">' . "\n" .
			'<UserId>' . $this->userId . '</UserId>' . "\n" .
			'<Title>' . wrapCData($this->title) . '</Title>' . "\n" .
			'<Vote>' . "\n" .
				'<VoteCnt>' . $this->voteCnt . '</VoteCnt>' . "\n" .
				'<YetVoted>' . ($this->yetVoted === true ? 1 : 0) . '</YetVoted>' . "\n" .
			'</Vote>' . "\n" .
			'<CategoryId>' . $subCategoryId . '</CategoryId>' . "\n" .
		'</'.$tagName.'>';
	}
}

class OfferedTopic extends Topic {
	
	private $offeredTopicId;
	private $offeredCategoryId;
	
	public function OfferedTopic($topicId, $userId, $title, $created, $voteCnt, $yetVoted,
			$offeredTopicId, $offeredCategoryId) {
		parent::__construct($topicId, $userId, $title, $created, $voteCnt, $yetVoted);
		
		$this->offeredTopicId = $offeredTopicId;
		$this->offeredCategoryId = $offeredCategoryId;
	}
	
	public function toXmlString() {
		return $this->xmlStringTemplate('OfferedTopic', $this->offeredTopicId, $this->offeredCategoryId);
	}
	
}


class NeededTopic extends Topic {
	
	private $neededTopicId;
	private $neededCategoryId;
	
	public function NeededTopic($topicId, $userId, $title, $created, $voteCnt, $yetVoted,
			$neededTopicId, $neededCategoryId) {
		parent::__construct($topicId, $userId, $title, $created, $voteCnt, $yetVoted);
		
		$this->neededTopicId = $neededTopicId;
		$this->neededCategoryId = $neededCategoryId;
	}
	
	public function toXmlString() {
		return $this->xmlStringTemplate('NeededTopic', $this->neededTopicId, $this->neededCategoryId);
	}
}

?>